package cn.sh.yhk.service.basic.impl;

import cn.sh.yhk.mapper.basic.JdbcMapper;
import cn.sh.yhk.mapper.basic.SCommonSqlMapper;
import cn.sh.yhk.mapper.basic.SUserMapper;
import cn.sh.yhk.model.basic.SCommonSql;
import cn.sh.yhk.model.basic.SCommonSqlExample;
import cn.sh.yhk.model.basic.SUser;
import cn.sh.yhk.model.basic.SUserExample;
import cn.sh.yhk.service.basic.JdbcService;
import cn.sh.yhk.vo.BasicVo;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.io.IOException;
import java.util.List;
import java.util.Map;

/**
 * @Auther: adminyhk
 * @Date: 2018/10/31 08:31
 * @Description:
 */
@Service
public class JdbcServiceImpl implements JdbcService {

    @Resource
    JdbcMapper jdbcMapper;
    @Resource
    SUserMapper sUserMapper;


    @Resource
    SCommonSqlMapper sCommonSqlMapper;


    public BasicVo getSql(String name) {
        SCommonSqlExample example = new SCommonSqlExample();
        example.createCriteria().andSqlNameEqualTo(name);
        List<SCommonSql> sql = sCommonSqlMapper.selectByExample(example);
        List<Map> ret = jdbcMapper.getSql(sql.get(0).getSqlText());
        return BasicVo.success("请求成功", ret);

    }

    @Transactional
    public void initpp() throws IOException {
        SUserExample sUserExample = new SUserExample();
        sUserExample.createCriteria().andUserIdEqualTo(1l);
        System.out.println(sUserMapper.selectByExample(sUserExample).get(0).getUserName());
        SUser user = new SUser();
        user.setAddress1("111111");
        sUserMapper.updateByExampleSelective(user, sUserExample);
        System.out.println(sUserMapper.selectByExample(sUserExample).get(0).getUserName());
    }
}
